const Router = require('koa-router')
const jwt = require('koa-jwt')
const router = new Router({ prefix: '/questions/:questionId/answers' })
const {
  checkAnswerExist,
  checkAnswerer,
  find,
  findById,
  create,
  update,
  delete: del
} = require('../controllers/answers')
const { SECRET } = require('../config')
const auth = jwt({ secret: SECRET })
// 获取问题列表
router.get('/', find)
// 获取指定问题
router.get('/:id', checkAnswerExist, findById)
// 新建问题
router.post('/', auth, create)
// 修改指定问题
router.patch('/:id', auth, checkAnswerExist, checkAnswerer, update)
// 删除指定问题
router.delete('/:id', auth, checkAnswerExist, checkAnswerer, del)
module.exports = router
